import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import pptv from 'postcss-px-to-viewport-8-plugin';

import path, { resolve } from 'path';

import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
// https://blog.csdn.net/m0_38134431/article/details/125508459

const pathResolve = (pathStr) => {
  return path.resolve(__dirname, pathStr);
};

const loader_px2vw: any = pptv({
  viewportWidth: 1920,
  viewportUnit: 'vw'
});

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    createSvgIconsPlugin({
      iconDirs: [pathResolve('./src/assets/svg')],
      // 指定symbolId格式（这里的配置与6.2步骤中的引入svg组件的name配置项写法有关）
      symbolId: 'icon-[dir]-[name]'
    })
  ],
  css: {
    preprocessorOptions: {
      less: {
        charset: false,
        additionalData: '@import "./src/common.less";'
      }
    }
  },
  resolve: {
    // 设置路径别名
    alias: {
      'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
      '@': pathResolve('./src')
    }
  },
  server: {
    proxy: {
      '/api': {
        target: 'https://server.caijiwang.cc/',
        changeOrigin: true
      }
    }
  }
});
